import pymysql


class MySql:
    def __init__(self, db_name):
        self.connection = pymysql.Connect(
            host='119.96.229.199',
            port=3306,
            user='root',
            passwd='sa1992',
            db=db_name,
            charset='utf8'
        )

    def query(self, sql):
        try:
            with self.connection.cursor() as cursor:
                cursor.execute(sql)
                result = cursor.fetchall()
                self.connection.commit()
                return result
        finally:
            self.connection.close()
